﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.ModBus
{
	/// <summary>
	/// Modbus-Udp协议的客户端通讯类，方便的和服务器进行数据交互，支持标准的功能码，也支持扩展的功能码实现，地址采用富文本的形式，详细见备注说明<br />
	/// The client communication class of Modbus-Udp protocol is convenient for data interaction with the server. It supports standard function codes and also supports extended function codes. 
	/// The address is in rich text. For details, see the remarks.
	/// </summary>
	/// <remarks>
	/// 本客户端支持的标准的modbus协议，Modbus-Tcp及Modbus-Udp内置的消息号会进行自增，地址支持富文本格式，具体参考示例代码。<br />
	/// 读取线圈，输入线圈，寄存器，输入寄存器的方法中的读取长度对商业授权用户不限制，内部自动切割读取，结果合并。
	/// </remarks>
	/// <example>
	/// <inheritdoc cref="T:HslCommunication.ModBus.ModbusTcpNet" path="example" />
	/// </example>
	// Token: 0x020000D3 RID: 211
	public class ModbusUdpNet : NetworkUdpDeviceBase
	{
		/// <summary>
		/// 实例化一个MOdbus-Udp协议的客户端对象<br />
		/// Instantiate a client object of the MOdbus-Udp protocol
		/// </summary>
		// Token: 0x06001084 RID: 4228 RVA: 0x0005FE14 File Offset: 0x0005E014
		public ModbusUdpNet()
		{
			base.ByteTransform = new ReverseWordTransform();
			this.softIncrementCount = new SoftIncrementCount(65535L, 0L, 1);
			base.WordLength = 1;
			this.station = 1;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.#ctor(System.String,System.Int32,System.Byte)" />
		// Token: 0x06001085 RID: 4229 RVA: 0x0005FE68 File Offset: 0x0005E068
		public ModbusUdpNet(string ipAddress, int port = 502, byte station = 1)
		{
			base.ByteTransform = new ReverseWordTransform();
			this.softIncrementCount = new SoftIncrementCount(65535L, 0L, 1);
			this.IpAddress = ipAddress;
			this.Port = port;
			base.WordLength = 1;
			this.station = station;
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.AddressStartWithZero" />
		// Token: 0x17000253 RID: 595
		// (get) Token: 0x06001086 RID: 4230 RVA: 0x0005FECC File Offset: 0x0005E0CC
		// (set) Token: 0x06001087 RID: 4231 RVA: 0x0005FEE4 File Offset: 0x0005E0E4
		public bool AddressStartWithZero
		{
			get
			{
				return this.isAddressStartWithZero;
			}
			set
			{
				this.isAddressStartWithZero = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.Station" />
		// Token: 0x17000254 RID: 596
		// (get) Token: 0x06001088 RID: 4232 RVA: 0x0005FEF0 File Offset: 0x0005E0F0
		// (set) Token: 0x06001089 RID: 4233 RVA: 0x0005FF08 File Offset: 0x0005E108
		public byte Station
		{
			get
			{
				return this.station;
			}
			set
			{
				this.station = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.DataFormat" />
		// Token: 0x17000255 RID: 597
		// (get) Token: 0x0600108A RID: 4234 RVA: 0x0005FF14 File Offset: 0x0005E114
		// (set) Token: 0x0600108B RID: 4235 RVA: 0x0005FF31 File Offset: 0x0005E131
		public DataFormat DataFormat
		{
			get
			{
				return base.ByteTransform.DataFormat;
			}
			set
			{
				base.ByteTransform.DataFormat = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.IsStringReverse" />
		// Token: 0x17000256 RID: 598
		// (get) Token: 0x0600108C RID: 4236 RVA: 0x0005FF44 File Offset: 0x0005E144
		// (set) Token: 0x0600108D RID: 4237 RVA: 0x0005FF61 File Offset: 0x0005E161
		public bool IsStringReverse
		{
			get
			{
				return base.ByteTransform.IsStringReverseByteWord;
			}
			set
			{
				base.ByteTransform.IsStringReverseByteWord = value;
			}
		}

		/// <inheritdoc cref="P:HslCommunication.ModBus.ModbusTcpNet.MessageId" />
		// Token: 0x17000257 RID: 599
		// (get) Token: 0x0600108E RID: 4238 RVA: 0x0005FF71 File Offset: 0x0005E171
		public SoftIncrementCount MessageId
		{
			get
			{
				return this.softIncrementCount;
			}
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoil(System.String)" />
		// Token: 0x0600108F RID: 4239 RVA: 0x0005FF79 File Offset: 0x0005E179
		public OperateResult<bool> ReadCoil(string address)
		{
			return this.ReadBool(address);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoil(System.String,System.UInt16)" />
		// Token: 0x06001090 RID: 4240 RVA: 0x0005FF82 File Offset: 0x0005E182
		public OperateResult<bool[]> ReadCoil(string address, ushort length)
		{
			return this.ReadBool(address, length);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadDiscrete(System.String)" />
		// Token: 0x06001091 RID: 4241 RVA: 0x0005FF8C File Offset: 0x0005E18C
		public OperateResult<bool> ReadDiscrete(string address)
		{
			return ByteTransformHelper.GetResultFromArray<bool>(this.ReadDiscrete(address, 1));
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusUdpNet.ReadDiscrete(System.String,System.UInt16)" />
		// Token: 0x06001092 RID: 4242 RVA: 0x0005FF9B File Offset: 0x0005E19B
		public OperateResult<bool[]> ReadDiscrete(string address, ushort length)
		{
			return this.ReadBoolHelper(address, length, 2);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Read(System.String,System.UInt16)" />
		// Token: 0x06001093 RID: 4243 RVA: 0x0005FFA8 File Offset: 0x0005E1A8
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<byte[][]> operateResult = ModbusInfo.BuildReadModbusCommand(address, length, this.Station, this.AddressStartWithZero, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				List<byte> list = new List<byte>();
				for (int i = 0; i < operateResult.Content.Length; i++)
				{
					OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content[i], (ushort)this.softIncrementCount.GetCurrentValue()));
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					OperateResult<byte[]> operateResult3 = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						return OperateResult.CreateFailedResult<byte[]>(operateResult3);
					}
					list.AddRange(operateResult3.Content);
				}
				result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Byte[])" />
		// Token: 0x06001094 RID: 4244 RVA: 0x00060094 File Offset: 0x0005E294
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Int16)" />
		// Token: 0x06001095 RID: 4245 RVA: 0x00060110 File Offset: 0x0005E310
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.UInt16)" />
		// Token: 0x06001096 RID: 4246 RVA: 0x0006018C File Offset: 0x0005E38C
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteWordModbusCommand(address, value, this.Station, this.AddressStartWithZero, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteMask(System.String,System.UInt16,System.UInt16)" />
		// Token: 0x06001097 RID: 4247 RVA: 0x00060208 File Offset: 0x0005E408
		[HslMqttApi("WriteMask", "")]
		public OperateResult WriteMask(string address, ushort andMask, ushort orMask)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteMaskModbusCommand(address, andMask, orMask, this.Station, this.AddressStartWithZero, 22);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteOneRegister(System.String,System.Int16)" />
		// Token: 0x06001098 RID: 4248 RVA: 0x00060283 File Offset: 0x0005E483
		public OperateResult WriteOneRegister(string address, short value)
		{
			return this.Write(address, value);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteOneRegister(System.String,System.UInt16)" />
		// Token: 0x06001099 RID: 4249 RVA: 0x0006028D File Offset: 0x0005E48D
		public OperateResult WriteOneRegister(string address, ushort value)
		{
			return this.Write(address, value);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoilAsync(System.String)" />
		// Token: 0x0600109A RID: 4250 RVA: 0x00060298 File Offset: 0x0005E498
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadCoilAsync(string address)
		{
			ModbusUdpNet.<ReadCoilAsync>d__30 <ReadCoilAsync>d__ = new ModbusUdpNet.<ReadCoilAsync>d__30();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<ModbusUdpNet.<ReadCoilAsync>d__30>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadCoilAsync(System.String,System.UInt16)" />
		// Token: 0x0600109B RID: 4251 RVA: 0x000602E4 File Offset: 0x0005E4E4
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadCoilAsync(string address, ushort length)
		{
			ModbusUdpNet.<ReadCoilAsync>d__31 <ReadCoilAsync>d__ = new ModbusUdpNet.<ReadCoilAsync>d__31();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.length = length;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<ModbusUdpNet.<ReadCoilAsync>d__31>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadDiscreteAsync(System.String)" />
		// Token: 0x0600109C RID: 4252 RVA: 0x00060338 File Offset: 0x0005E538
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadDiscreteAsync(string address)
		{
			ModbusUdpNet.<ReadDiscreteAsync>d__32 <ReadDiscreteAsync>d__ = new ModbusUdpNet.<ReadDiscreteAsync>d__32();
			<ReadDiscreteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadDiscreteAsync>d__.<>4__this = this;
			<ReadDiscreteAsync>d__.address = address;
			<ReadDiscreteAsync>d__.<>1__state = -1;
			<ReadDiscreteAsync>d__.<>t__builder.Start<ModbusUdpNet.<ReadDiscreteAsync>d__32>(ref <ReadDiscreteAsync>d__);
			return <ReadDiscreteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadDiscreteAsync(System.String,System.UInt16)" />
		// Token: 0x0600109D RID: 4253 RVA: 0x00060384 File Offset: 0x0005E584
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadDiscreteAsync(string address, ushort length)
		{
			ModbusUdpNet.<ReadDiscreteAsync>d__33 <ReadDiscreteAsync>d__ = new ModbusUdpNet.<ReadDiscreteAsync>d__33();
			<ReadDiscreteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadDiscreteAsync>d__.<>4__this = this;
			<ReadDiscreteAsync>d__.address = address;
			<ReadDiscreteAsync>d__.length = length;
			<ReadDiscreteAsync>d__.<>1__state = -1;
			<ReadDiscreteAsync>d__.<>t__builder.Start<ModbusUdpNet.<ReadDiscreteAsync>d__33>(ref <ReadDiscreteAsync>d__);
			return <ReadDiscreteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusUdpNet.Write(System.String,System.Int16)" />/param&gt;
		// Token: 0x0600109E RID: 4254 RVA: 0x000603D8 File Offset: 0x0005E5D8
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, short value)
		{
			ModbusUdpNet.<WriteAsync>d__34 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__34();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__34>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusUdpNet.Write(System.String,System.UInt16)" />/param&gt;
		// Token: 0x0600109F RID: 4255 RVA: 0x0006042C File Offset: 0x0005E62C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ushort value)
		{
			ModbusUdpNet.<WriteAsync>d__35 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__35();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__35>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteOneRegister(System.String,System.Int16)" />
		// Token: 0x060010A0 RID: 4256 RVA: 0x00060480 File Offset: 0x0005E680
		[DebuggerStepThrough]
		public Task<OperateResult> WriteOneRegisterAsync(string address, short value)
		{
			ModbusUdpNet.<WriteOneRegisterAsync>d__36 <WriteOneRegisterAsync>d__ = new ModbusUdpNet.<WriteOneRegisterAsync>d__36();
			<WriteOneRegisterAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteOneRegisterAsync>d__.<>4__this = this;
			<WriteOneRegisterAsync>d__.address = address;
			<WriteOneRegisterAsync>d__.value = value;
			<WriteOneRegisterAsync>d__.<>1__state = -1;
			<WriteOneRegisterAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteOneRegisterAsync>d__36>(ref <WriteOneRegisterAsync>d__);
			return <WriteOneRegisterAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteOneRegister(System.String,System.UInt16)" />
		// Token: 0x060010A1 RID: 4257 RVA: 0x000604D4 File Offset: 0x0005E6D4
		[DebuggerStepThrough]
		public Task<OperateResult> WriteOneRegisterAsync(string address, ushort value)
		{
			ModbusUdpNet.<WriteOneRegisterAsync>d__37 <WriteOneRegisterAsync>d__ = new ModbusUdpNet.<WriteOneRegisterAsync>d__37();
			<WriteOneRegisterAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteOneRegisterAsync>d__.<>4__this = this;
			<WriteOneRegisterAsync>d__.address = address;
			<WriteOneRegisterAsync>d__.value = value;
			<WriteOneRegisterAsync>d__.<>1__state = -1;
			<WriteOneRegisterAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteOneRegisterAsync>d__37>(ref <WriteOneRegisterAsync>d__);
			return <WriteOneRegisterAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteMask(System.String,System.UInt16,System.UInt16)" />
		// Token: 0x060010A2 RID: 4258 RVA: 0x00060528 File Offset: 0x0005E728
		[DebuggerStepThrough]
		public Task<OperateResult> WriteMaskAsync(string address, ushort andMask, ushort orMask)
		{
			ModbusUdpNet.<WriteMaskAsync>d__38 <WriteMaskAsync>d__ = new ModbusUdpNet.<WriteMaskAsync>d__38();
			<WriteMaskAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteMaskAsync>d__.<>4__this = this;
			<WriteMaskAsync>d__.address = address;
			<WriteMaskAsync>d__.andMask = andMask;
			<WriteMaskAsync>d__.orMask = orMask;
			<WriteMaskAsync>d__.<>1__state = -1;
			<WriteMaskAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteMaskAsync>d__38>(ref <WriteMaskAsync>d__);
			return <WriteMaskAsync>d__.<>t__builder.Task;
		}

		// Token: 0x060010A3 RID: 4259 RVA: 0x00060584 File Offset: 0x0005E784
		private OperateResult<bool[]> ReadBoolHelper(string address, ushort length, byte function)
		{
			OperateResult<byte[][]> operateResult = ModbusInfo.BuildReadModbusCommand(address, length, this.Station, this.AddressStartWithZero, function);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				List<bool> list = new List<bool>();
				for (int i = 0; i < operateResult.Content.Length; i++)
				{
					OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content[i], (ushort)this.softIncrementCount.GetCurrentValue()));
					bool flag2 = !operateResult2.IsSuccess;
					if (flag2)
					{
						return OperateResult.CreateFailedResult<bool[]>(operateResult2);
					}
					OperateResult<byte[]> operateResult3 = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						return OperateResult.CreateFailedResult<bool[]>(operateResult3);
					}
					int length2 = (int)operateResult.Content[i][4] * 256 + (int)operateResult.Content[i][5];
					list.AddRange(SoftBasic.ByteToBoolArray(operateResult3.Content, length2));
				}
				result = OperateResult.CreateSuccessResult<bool[]>(list.ToArray());
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.ReadBool(System.String,System.UInt16)" />
		// Token: 0x060010A4 RID: 4260 RVA: 0x0006069A File Offset: 0x0005E89A
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			return this.ReadBoolHelper(address, length, 1);
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Boolean[])" />
		// Token: 0x060010A5 RID: 4261 RVA: 0x000606A8 File Offset: 0x0005E8A8
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteBoolModbusCommand(address, values, this.Station, this.AddressStartWithZero, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.Write(System.String,System.Boolean)" />
		// Token: 0x060010A6 RID: 4262 RVA: 0x00060724 File Offset: 0x0005E924
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<byte[]> operateResult = ModbusInfo.BuildWriteBoolModbusCommand(address, value, this.Station, this.AddressStartWithZero, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = this.ReadFromCoreServer(ModbusInfo.PackCommandToTcp(operateResult.Content, (ushort)this.softIncrementCount.GetCurrentValue()));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = ModbusInfo.ExtractActualData(ModbusInfo.ExplodeTcpCommandToCore(operateResult2.Content));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.ModBus.ModbusTcpNet.WriteAsync(System.String,System.Boolean)" />
		// Token: 0x060010A7 RID: 4263 RVA: 0x000607A0 File Offset: 0x0005E9A0
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			ModbusUdpNet.<WriteAsync>d__43 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__43();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__43>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt32(System.String,System.UInt16)" />
		// Token: 0x060010A8 RID: 4264 RVA: 0x000607F4 File Offset: 0x0005E9F4
		[HslMqttApi("ReadInt32Array", "")]
		public override OperateResult<int[]> ReadInt32(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<int[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransInt32(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt32(System.String,System.UInt16)" />
		// Token: 0x060010A9 RID: 4265 RVA: 0x00060850 File Offset: 0x0005EA50
		[HslMqttApi("ReadUInt32Array", "")]
		public override OperateResult<uint[]> ReadUInt32(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<uint[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransUInt32(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadFloat(System.String,System.UInt16)" />
		// Token: 0x060010AA RID: 4266 RVA: 0x000608AC File Offset: 0x0005EAAC
		[HslMqttApi("ReadFloatArray", "")]
		public override OperateResult<float[]> ReadFloat(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<float[]>(this.Read(address, length * base.WordLength * 2), (byte[] m) => transform.TransSingle(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt64(System.String,System.UInt16)" />
		// Token: 0x060010AB RID: 4267 RVA: 0x00060908 File Offset: 0x0005EB08
		[HslMqttApi("ReadInt64Array", "")]
		public override OperateResult<long[]> ReadInt64(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<long[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransInt64(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt64(System.String,System.UInt16)" />
		// Token: 0x060010AC RID: 4268 RVA: 0x00060964 File Offset: 0x0005EB64
		[HslMqttApi("ReadUInt64Array", "")]
		public override OperateResult<ulong[]> ReadUInt64(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<ulong[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransUInt64(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadDouble(System.String,System.UInt16)" />
		// Token: 0x060010AD RID: 4269 RVA: 0x000609C0 File Offset: 0x0005EBC0
		[HslMqttApi("ReadDoubleArray", "")]
		public override OperateResult<double[]> ReadDouble(string address, ushort length)
		{
			IByteTransform transform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return ByteTransformHelper.GetResultFromBytes<double[]>(this.Read(address, length * base.WordLength * 4), (byte[] m) => transform.TransDouble(m, 0, (int)length));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Int32[])" />
		// Token: 0x060010AE RID: 4270 RVA: 0x00060A1C File Offset: 0x0005EC1C
		[HslMqttApi("WriteInt32Array", "")]
		public override OperateResult Write(string address, int[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.UInt32[])" />
		// Token: 0x060010AF RID: 4271 RVA: 0x00060A4C File Offset: 0x0005EC4C
		[HslMqttApi("WriteUInt32Array", "")]
		public override OperateResult Write(string address, uint[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Single[])" />
		// Token: 0x060010B0 RID: 4272 RVA: 0x00060A7C File Offset: 0x0005EC7C
		[HslMqttApi("WriteFloatArray", "")]
		public override OperateResult Write(string address, float[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Int64[])" />
		// Token: 0x060010B1 RID: 4273 RVA: 0x00060AAC File Offset: 0x0005ECAC
		[HslMqttApi("WriteInt64Array", "")]
		public override OperateResult Write(string address, long[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.UInt64[])" />
		// Token: 0x060010B2 RID: 4274 RVA: 0x00060ADC File Offset: 0x0005ECDC
		[HslMqttApi("WriteUInt64Array", "")]
		public override OperateResult Write(string address, ulong[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.Write(System.String,System.Double[])" />
		// Token: 0x060010B3 RID: 4275 RVA: 0x00060B0C File Offset: 0x0005ED0C
		[HslMqttApi("WriteDoubleArray", "")]
		public override OperateResult Write(string address, double[] values)
		{
			IByteTransform byteTransform = HslHelper.ExtractTransformParameter(ref address, base.ByteTransform);
			return this.Write(address, byteTransform.TransByte(values));
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt32Async(System.String,System.UInt16)" />
		// Token: 0x060010B4 RID: 4276 RVA: 0x00060B3C File Offset: 0x0005ED3C
		[DebuggerStepThrough]
		public override Task<OperateResult<int[]>> ReadInt32Async(string address, ushort length)
		{
			ModbusUdpNet.<ReadInt32Async>d__56 <ReadInt32Async>d__ = new ModbusUdpNet.<ReadInt32Async>d__56();
			<ReadInt32Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<int[]>>.Create();
			<ReadInt32Async>d__.<>4__this = this;
			<ReadInt32Async>d__.address = address;
			<ReadInt32Async>d__.length = length;
			<ReadInt32Async>d__.<>1__state = -1;
			<ReadInt32Async>d__.<>t__builder.Start<ModbusUdpNet.<ReadInt32Async>d__56>(ref <ReadInt32Async>d__);
			return <ReadInt32Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt32Async(System.String,System.UInt16)" />
		// Token: 0x060010B5 RID: 4277 RVA: 0x00060B90 File Offset: 0x0005ED90
		[DebuggerStepThrough]
		public override Task<OperateResult<uint[]>> ReadUInt32Async(string address, ushort length)
		{
			ModbusUdpNet.<ReadUInt32Async>d__57 <ReadUInt32Async>d__ = new ModbusUdpNet.<ReadUInt32Async>d__57();
			<ReadUInt32Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<uint[]>>.Create();
			<ReadUInt32Async>d__.<>4__this = this;
			<ReadUInt32Async>d__.address = address;
			<ReadUInt32Async>d__.length = length;
			<ReadUInt32Async>d__.<>1__state = -1;
			<ReadUInt32Async>d__.<>t__builder.Start<ModbusUdpNet.<ReadUInt32Async>d__57>(ref <ReadUInt32Async>d__);
			return <ReadUInt32Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadFloatAsync(System.String,System.UInt16)" />
		// Token: 0x060010B6 RID: 4278 RVA: 0x00060BE4 File Offset: 0x0005EDE4
		[DebuggerStepThrough]
		public override Task<OperateResult<float[]>> ReadFloatAsync(string address, ushort length)
		{
			ModbusUdpNet.<ReadFloatAsync>d__58 <ReadFloatAsync>d__ = new ModbusUdpNet.<ReadFloatAsync>d__58();
			<ReadFloatAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<float[]>>.Create();
			<ReadFloatAsync>d__.<>4__this = this;
			<ReadFloatAsync>d__.address = address;
			<ReadFloatAsync>d__.length = length;
			<ReadFloatAsync>d__.<>1__state = -1;
			<ReadFloatAsync>d__.<>t__builder.Start<ModbusUdpNet.<ReadFloatAsync>d__58>(ref <ReadFloatAsync>d__);
			return <ReadFloatAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadInt64Async(System.String,System.UInt16)" />
		// Token: 0x060010B7 RID: 4279 RVA: 0x00060C38 File Offset: 0x0005EE38
		[DebuggerStepThrough]
		public override Task<OperateResult<long[]>> ReadInt64Async(string address, ushort length)
		{
			ModbusUdpNet.<ReadInt64Async>d__59 <ReadInt64Async>d__ = new ModbusUdpNet.<ReadInt64Async>d__59();
			<ReadInt64Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<long[]>>.Create();
			<ReadInt64Async>d__.<>4__this = this;
			<ReadInt64Async>d__.address = address;
			<ReadInt64Async>d__.length = length;
			<ReadInt64Async>d__.<>1__state = -1;
			<ReadInt64Async>d__.<>t__builder.Start<ModbusUdpNet.<ReadInt64Async>d__59>(ref <ReadInt64Async>d__);
			return <ReadInt64Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadUInt64Async(System.String,System.UInt16)" />
		// Token: 0x060010B8 RID: 4280 RVA: 0x00060C8C File Offset: 0x0005EE8C
		[DebuggerStepThrough]
		public override Task<OperateResult<ulong[]>> ReadUInt64Async(string address, ushort length)
		{
			ModbusUdpNet.<ReadUInt64Async>d__60 <ReadUInt64Async>d__ = new ModbusUdpNet.<ReadUInt64Async>d__60();
			<ReadUInt64Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<ulong[]>>.Create();
			<ReadUInt64Async>d__.<>4__this = this;
			<ReadUInt64Async>d__.address = address;
			<ReadUInt64Async>d__.length = length;
			<ReadUInt64Async>d__.<>1__state = -1;
			<ReadUInt64Async>d__.<>t__builder.Start<ModbusUdpNet.<ReadUInt64Async>d__60>(ref <ReadUInt64Async>d__);
			return <ReadUInt64Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.ReadDoubleAsync(System.String,System.UInt16)" />
		// Token: 0x060010B9 RID: 4281 RVA: 0x00060CE0 File Offset: 0x0005EEE0
		[DebuggerStepThrough]
		public override Task<OperateResult<double[]>> ReadDoubleAsync(string address, ushort length)
		{
			ModbusUdpNet.<ReadDoubleAsync>d__61 <ReadDoubleAsync>d__ = new ModbusUdpNet.<ReadDoubleAsync>d__61();
			<ReadDoubleAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<double[]>>.Create();
			<ReadDoubleAsync>d__.<>4__this = this;
			<ReadDoubleAsync>d__.address = address;
			<ReadDoubleAsync>d__.length = length;
			<ReadDoubleAsync>d__.<>1__state = -1;
			<ReadDoubleAsync>d__.<>t__builder.Start<ModbusUdpNet.<ReadDoubleAsync>d__61>(ref <ReadDoubleAsync>d__);
			return <ReadDoubleAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Int32[])" />
		// Token: 0x060010BA RID: 4282 RVA: 0x00060D34 File Offset: 0x0005EF34
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, int[] values)
		{
			ModbusUdpNet.<WriteAsync>d__62 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__62();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__62>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.UInt32[])" />
		// Token: 0x060010BB RID: 4283 RVA: 0x00060D88 File Offset: 0x0005EF88
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, uint[] values)
		{
			ModbusUdpNet.<WriteAsync>d__63 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__63();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__63>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Single[])" />
		// Token: 0x060010BC RID: 4284 RVA: 0x00060DDC File Offset: 0x0005EFDC
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, float[] values)
		{
			ModbusUdpNet.<WriteAsync>d__64 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__64();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__64>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Int64[])" />
		// Token: 0x060010BD RID: 4285 RVA: 0x00060E30 File Offset: 0x0005F030
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, long[] values)
		{
			ModbusUdpNet.<WriteAsync>d__65 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__65();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__65>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.UInt64[])" />
		// Token: 0x060010BE RID: 4286 RVA: 0x00060E84 File Offset: 0x0005F084
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, ulong[] values)
		{
			ModbusUdpNet.<WriteAsync>d__66 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__66();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__66>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IReadWriteNet.WriteAsync(System.String,System.Double[])" />
		// Token: 0x060010BF RID: 4287 RVA: 0x00060ED8 File Offset: 0x0005F0D8
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, double[] values)
		{
			ModbusUdpNet.<WriteAsync>d__67 <WriteAsync>d__ = new ModbusUdpNet.<WriteAsync>d__67();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ModbusUdpNet.<WriteAsync>d__67>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x060010C0 RID: 4288 RVA: 0x00060F2A File Offset: 0x0005F12A
		public override string ToString()
		{
			return string.Format("ModbusUdpNet[{0}:{1}]", this.IpAddress, this.Port);
		}

		// Token: 0x04000446 RID: 1094
		private byte station = 1;

		// Token: 0x04000447 RID: 1095
		private SoftIncrementCount softIncrementCount;

		// Token: 0x04000448 RID: 1096
		private bool isAddressStartWithZero = true;
	}
}
